﻿(function () {
    "use strict";

    WinJS.UI.Pages.define("/pages/login/login.html", {
        // This function is called whenever a user navigates to this page. It
        // populates the page elements with the app's data.
        ready: function (element, options) {
            // TODO: Initialize the page here.
            $('#-login-submin').click(function () {
                var _user = $('#-login-user').val().trim();
                var _pwd = $('#-login-pwd').val().trim();

                if (_user == '') {
                    $('#-register-error').text('User name can\'t be empty!');
                    return;
                }
                if (_pwd == '') {
                    $('#-register-error').text('Password can\'t be empty!');
                    return;
                }

                var _userStore = Ext.StoreMgr.lookup('SafeBox.Store.UserStore');
                var _result = _userStore.check(_user, _pwd);
                if (_result == Constants.LoginResult.Success) {
                    WinJS.Navigation.navigate("/pages/home/home.html");
                }
                else if (_result == Constants.LoginResult.PasswordNotMatch) {
                    $('#-register-error').text('Password is not correct!');
                }
                else if (_result == Constants.LoginResult.UserNotExist) {
                    $('#-register-error').text('User name does not exist!');
                }
            });
        }
    });
})();
